package com.ea.admin.controller.tutelage;

import com.ea.admin.pojo.param.report.GetReportListParam;
import com.ea.admin.service.HistoryReportService;
import com.ea.admin.utils.NowUserGetter;
import com.ea.common.auth.NowUser;
import com.ea.common.log.LogAnnotation;
import com.ea.common.report.pojo.vo.ReportSimpleInfoListVo;
import com.ea.common.result.BizException;
import com.ea.common.result.ErrorCode;
import com.ea.common.result.Result;
import com.ea.common.utils.ParamUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@Api(tags = "监护管理-历史报告")
@RequestMapping("/admin/historyReport")
public class HistoryReportController {

    @Resource
    HistoryReportService historyReportService;
    @Resource
    NowUserGetter nowUserGetter;

    @Transactional
    @Operation(summary = "获得所有报告")
    @PostMapping("/getReportList")
    @ApiImplicitParam(dataType = "GetReportListParam", name = "getReportListParam", value = "获得报告", readOnly = true, required = true)
    @LogAnnotation(module = "ReportController", operation = "获得报告")
    public Result<ReportSimpleInfoListVo> getReportList(@RequestBody @Valid GetReportListParam getReportListParam) {
        NowUser nowUser = nowUserGetter.getNowUser();
        if (nowUser == null) {
            throw new BizException(ErrorCode.USER_LOGIN_ERROR_NO_LOGIN);
        }
        ReportSimpleInfoListVo result = historyReportService.getReportList(
                nowUser.getAccountId(),
                ParamUtil.parseIdList(getReportListParam.getCompanyIdList()),
                ParamUtil.parseIdList(getReportListParam.getDepartmentIdList()),
                ParamUtil.parseIdList(getReportListParam.getPositionIdList()),
                getReportListParam.getWarningTypeList(),
                getReportListParam.getStatusList(),
                getReportListParam.getName(),
                getReportListParam.getPostStartDate(),
                getReportListParam.getPostEndDate(),
                getReportListParam.getReceiveStartDate(),
                getReportListParam.getReceiveEndDate(),
                getReportListParam.getEmoAnalyStartDate(),
                getReportListParam.getEmoAnalyEndDate(),
                getReportListParam.getHeartRateStartDate(),
                getReportListParam.getHeartRateEndDate(),
                getReportListParam.getPage(),
                getReportListParam.getPageSize());
        return Result.success(result);
    }
}
